package com.imooc.ad.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

/**
 * Created by lzq on 2019/3/1
 */
@Component
@Slf4j
public class PreRequestFilter extends ZuulFilter{

    //zull 过滤器类型  pre filters; routing filters; post filters; err filters.
    @Override
    public String filterType() {
        return FilterConstants.PRE_TYPE;
    }

    //执行顺序  数值越小优先级越高
    @Override
    public int filterOrder() {
        return 0;
    }

    //是否必须执行
    @Override
    public boolean shouldFilter() {
        return true;
    }

    //业务逻辑处理
    @Override
    public Object run() throws ZuulException {


        RequestContext ctx = RequestContext.getCurrentContext();
        ctx.set("startTime", System.currentTimeMillis());
        return null;
    }


}
